package com.gxa.controller;

import com.gxa.common.Constants;
import com.gxa.common.PaginationResult;
import com.gxa.common.ResponseData;
import com.gxa.pojo.Groups;
import com.gxa.service.GroupService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * Created with IntelliJ IDEA.
 * User: tx
 * Date: 2020/10/27 11:14
 * Description:设置分组接口设置
 * Version: V1.0
 */
@RestController
@RequestMapping("group")
@Api(value = "添加员工分组",tags = "设置分组")
public class GroupController {

    @Autowired
    private GroupService groupService;
    @Autowired
    private ResponseData responseData;
    @PostMapping("/addEmployeeGroup")
    @ApiOperation(value = "添加员工分组接口", notes = "根据信息添加员工分组信息接口", httpMethod = "post", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "添加成功"),
            @ApiResponse(code = 400, message = "找不到页面"),
            @ApiResponse(code = 500, message = "添加失败")
    })
    public ResponseData addEmployeeGroup(@RequestBody @ApiParam(name = "employee",value = "员工信息",required = true) Groups groups){
        int result = groupService.addEmployeeGroup(groups);
        if(result > 0){
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("添加成功");
            responseData.setData(null);
        }
        return responseData;
    }

    @PostMapping("/delEmployeeGroup")
    @ApiOperation(value = "删除员工分组接口", notes = "根据信息删除员工分组信息接口", httpMethod = "post", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "删除成功"),
            @ApiResponse(code = 400, message = "找不到页面"),
            @ApiResponse(code = 500, message = "删除失败")
    })
    public ResponseData delEmployeeGroup(@RequestBody @ApiParam(name = "groupId",value = "组id",required = true) Groups groups){
        int result = groupService.delEmployeeGroup(groups);
        if(result > 0){
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("删除成功");
            responseData.setData(groups.getGroupId());
        }
        return responseData;
    }


    @PostMapping("/updateEmployeeGroup")
    @ApiOperation(value = "更新员工分组接口", notes = "根据信息更新员工分组信息接口", httpMethod = "post", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "更新成功"),
            @ApiResponse(code = 400, message = "找不到页面"),
            @ApiResponse(code = 500, message = "更新失败")
    })
    public ResponseData updateEmployeeGroup(@RequestBody @ApiParam(name = "groupId",value = "组id",required = true)Groups groups){
        int result = groupService.updateEmployeeGroup(groups);
        if(result > 0){
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("更新成功");
            responseData.setData(groups.getGroupId());
        }
        return responseData;
    }


    @GetMapping("/queryEmployeeGroup")
    @ApiOperation(value = "查询员工分组接口", notes = "根据信息查询员工分组接口", httpMethod = "get", response = ResponseData.class)
    @ApiResponses({
            @ApiResponse(code = 200, message = "查询成功"),
            @ApiResponse(code = 400, message = "找不到页面"),
            @ApiResponse(code = 500, message = "查询失败")
    })
    public ResponseData queryEmployeeGroup(@RequestParam(defaultValue = "1") int currentPage, @RequestParam(defaultValue = "3")int pageSize){
        PaginationResult paginationResult = groupService.queryEmployeeGroup(currentPage,pageSize);
        if(paginationResult != null){
            responseData.setCode(Constants.SUCCESS);
            responseData.setMsg("查询成功");
            responseData.setData(paginationResult);
        }else{
            responseData.setCode(Constants.NOTFOUND);
            responseData.setMsg("没有找到相关的信息");
        }
        return responseData;
    }



}
